package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 *
 * @author Yanxinhao on 2025/2/14
 */

@Configuration
public class OrderInfoAutoConfiguration {

    //1.定义交换机
    @Bean
    public CustomExchange delayExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue delayQueue() {
        return new Queue(MqConst.QUEUE_CANCEL_ORDER,true,false,false);
    }

    @Bean
    public Binding  binding(CustomExchange delayExchange,Queue delayQueue) {
        return BindingBuilder.bind(delayQueue).to(delayExchange).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }


}